﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using KC.DataAccess.MV6;

public partial class Categories : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		MV6DataContext dc = new MV6DataContext(ConfigurationManager.ConnectionStrings["MV6"].ConnectionString);

		int CatID = -1;
		if (Master.values.ContainsKey("id")) CatID = int.Parse(Master.values["id"]);
		if (CatID >= 0)
		{
			var posts = from p in dc.Posts
						join cp in dc.CategoryToPosts
							on p.ID equals cp.PID
						where cp.CID == CatID
						orderby p.Created descending
						select p;
			rCatDetail.DataSource = posts;
			rCatDetail.DataBind();
		}

		var cats = from c in dc.Categories
				   orderby c.Title
				   select c;
		rCats.DataSource = cats;
		rCats.DataBind();
    }
}